// components/image-button/index.js
import { AppModel } from '../../../models/app.js'
const ModelApp = new AppModel()
const App = getApp()
Component({
  /**
   * 组件的属性列表
   */
  externalClasses: ['ex-class'],
  options: {
    multipleSlots: true
  },
  properties: {
    scode: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    iphoneX: App.globalData.isIphoneX
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 正品保证跳转
    topToIndexBanner: function() {
      const bannerUrl = 'https://admin.top1buyer.com/wxview/images'
      const query = 'genuine_2.jpg,license.jpg'
      wx.navigateTo({
        url: `/pages/home/webview/index?bannerUrl=${bannerUrl}&query=${query}`
      })
    },
    // 去签到分享
    goSign() {
      wx.navigateTo({
        url: `/pages/marketing/shareSign/index`
      })
    },
    //新手福利
    NewWelfare() {
      wx.navigateTo({
        url: `/pages/manager/task/index`
      })
    },
    //评论有奖
    comment() {
      //查询用户是否有已完成的订单
      const params = {}
      ModelApp.selectNumber(params)
        .then(res => {
          if (res.data.number.orderCompleted > 0) {
            wx.navigateTo({
              url: '/pages/account/order/list/index?index=' + 5
            })
          } else {
            wx.showToast({ title: '暂无可评价的订单', icon: 'none' })
          }
        })
        .catch()
    },
    //翻牌
    account() {
      // 查询活动是否开启关闭
      ModelApp.getCardStatus({ activityCode: '001' }).then(res => {
        //	时间标识 0活动未开始 1 活动已结束 2 活动进行中
        const status = res.data.date
        if (status == 0) {
          wx.showToast({ title: '活动未开始', icon: 'none' })
        } else if (status == 1) {
          wx.showToast({ title: '活动已结束', icon: 'none' })
        } else {
          wx.navigateTo({
            url: '/pages/marketing/gridcard/index'
          })
        }
      })
    }
  }
})
